package com.tb.controller;

import com.tb.model.Message;
import com.tb.model.Star;
import com.tb.service.MessageService;
import com.tb.service.StarService;
import com.tb.util.MyConstant;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;

/**
 * @description: 收藏相关
 * @author: wangguichun
 * @create: 2018-04-15 09:43
 **/

@Controller
@RequestMapping("star")
public class StarController {

    @Autowired
    private StarService starService;
    @Autowired
    private MessageService messageService;

    @RequestMapping("add")
    @ResponseBody
    public void add(Star star,int questionUserId){
        starService.addStarRecord(star);
        Message message = new Message();
        message.setFromId(star.getUserId());
        message.setToId(questionUserId);
        message.setType(MyConstant.ACT_STAR);
        message.setObjecId(star.getQuestionId());
        message.setTime(new Date().getTime());
        messageService.addMessage(message);
    }

    @RequestMapping("remove")
    @ResponseBody
    public void remove(Star star){
        starService.removeStarRecord(star);
    }




}
